package com.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.server.pojo.Orders;
import com.server.service.impl.OrdersServiceImpl;
import com.server.utils.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品订单记录表 前端控制器
 * </p>
 *
 * @author ckick
 * @since 2025-09-20 09:29:27
 */
@RestController
public class OrdersController {
    @Autowired
    OrdersServiceImpl ordersService;

    @RequestMapping("ordersPage")
    ResponseMsg ordersPage(@RequestParam(defaultValue = "1") Integer page,
                           @RequestParam(defaultValue = "5") Integer limit) {
        System.out.println("分页查询调起了");
        QueryWrapper<Orders> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("order_id");
        IPage<Orders> ordersIPage = ordersService.page(new Page<>(page, limit), wrapper);
        return ResponseMsg.getInstance(200, ordersIPage);
    }

    @RequestMapping("updateOrderStatus")
    ResponseMsg updateStatusByOrderId(@RequestParam Integer orderId,
                                      @RequestParam String status) {
        Orders orders = new Orders();
        orders.setOrderId(orderId);
        orders.setStatus(status);
        return ordersService.updateById(orders) ? ResponseMsg.success() : ResponseMsg.getInstance(ResponseMsg.ERROR, "修改失败");
    }
}
